<?php

// GMLP_DEF.PHP - GMLP definition file. This data is meant to be 
// modified/customized. See file GMLP.TXT for more information.

// The default functions beginning with 'gmlp_' are in gmlp_func.php which is 
// included elsewhere (see gmlp_open() in gmlp.php).

// UPDATE: Please note that these "rules" are just examples of things that can 
// be done, nothing more. It was made up for a very personalized blog.

// See MARKDOWN.PHP for Markdown syntax version of this file. See INDEX.PHP 
// for how to load and apply it.


// input text delimiters

$gmlp_translate['STRIP'] = '';		// mixed; $replace in str_replace()
$gmlp_translate['NEWLINE'] = "\n";	// delimiter for explode()

// the output paragraph and line terminators; break, wrap start/end, end

$gmlp_translate['EOL'] = array('<br>','<p>','</p>',"\n");
define('EOL_BR',0);
define('EOL_P1',1);
define('EOL_P2',2);
define('EOL_NL',3);

// the entity translate flag

$gmlp_translate['entitytranslate'] = 1;

// skip lines

$gmlp_translate['skip'] = array(
"/^`(.*)'$/",
);

// convert line to pragraph and then continue
// if value is '' use line as is; if value is function, function is called 
// with line or $1 if that sub-pattern is defined (this may change, see 
// code) and line is function return; else line is preg replaced; first two 
// conditions bypass all further conversions; parsed by gmlp_lines()

$gmlp_translate['lines'] = array(
// straight substitutions
'/^<hr>/' => '',
'/^<!--.*-->$/' => '',
// function call
'/^[A-Z \/&\?\'!]+$/' => 'gmlp_convertcase',
// center text ('inlines' and 'chars' conversions applied)
'/^\s{9,}(.*)/' => '<span style="display:block;text-align:center;">$1</span>',
// pre-defined classes
'/^<(indent|box|message|notice|note|small|center)>/' => '<div class="$1">',
'/^<\/(indent|box|message|notice|note|small|center)>/' => '</p></div>',
'/^~$/' => '<div class="tilde">~</div>',
// these are kind of goofy (although interesting)
'/^h([1-6]):\s*(.*)/' => '<h$1>$2</h$1>',
'/^bq:\s*(.*)/' => '<blockquote>$1</blockquote>',
'/^in:\s*(.*)/' => '<div style="text-indent:2em;">$1</div>',
'/^nt:\s*(.*)/' => '<div style="font-size:smaller;">$1</div>',
'/^cn:\s*(.*)/' => '<div style="text-align:center;">$1</div>',
);

// applied to lines being read as a paragraph (greedy enabled) and for block
// lines

$gmlp_translate['line'] = array(
'/^\t(.*)/' => '    $1',
);

// preg replaces
// these are applied in order from first to last which means translations 
// effect following translations; parsed by gmlp_inlines()

$gmlp_translate['inlines'] = array(
'/(\S+)\[\]([,. \)]+)/' => '$1<span class="nt"></span>$2',
'/(\S+)\[\]$/' => '$1<span class="nt"></span>',
'/`([^\']*)\'/U' => '<tt>`$1&#039;</tt>',
'/(http[s]*\S*)[:;,]([a-zA-Z0-9 ]+)/' => '<a href="$1">$2</a>',
'/""(.*)""/U' => '<em>"$1"</em>',
'/([A-Z_\/]+\.(INI|TXT|HTML|HTM|PHP)+)/' => '<code>$1</code>',
// these avoid other translations
'/\\\\\$/U' => '&#036;',
'/\\\\\'/U' => '&#039;',
'/\\\\\./U' => '&#046;',
// these values are function calls
'/\'\'(.*)\'\'/U' => 'htmlentities',
'/(<[A-Z]+>)/' =>'htmlentities', 
'/(<\/[A-Z]+>)/' =>'htmlentities', 
// NOTE: the order of these are important (see function)
'/([a-zA-Z_]+\([^\)]*\))/' => 'gmlp_php_string',
'/(\$[0-9]+)/' => 'gmlp_php_string',
'/(\$[^ .,;)]+)/' => 'gmlp_php_string',
);

// string substitutions

$gmlp_translate['entities'] = array(
' -- ' => '&mdash;',
'--' => '&mdash;',
);

// tag-ize words
// parsed by gmlp_chars()
// the from RE is: $repl = $wordbeg.$char.'(.*)'.$char.$wordend;
// the to text is: $tags = '$1<'.$tag.'>$2</'.$tag.'>$3';

$gmlp_translate['wordbeg'] = '/(^|[^a-zA-Z=;\/])';
$gmlp_translate['wordend'] = '([^a-zA-Z\/\]]|$)/U';

$gmlp_translate['chars'] = array(
'*' => 'b',
'_' => 'u',
'|' => 'tt',
'^' => 'i',
'\'' => 'code',
);

// block conversions
// some begin expressions lack a trailing '>' so that both of these work: 
//	<pre>
//	<pre class="foo">
// parsed by gmlp_convert_block()

$gmlp_translate['blocks']['php'] = array(
'begin' => '/^\s*<\?php/',			// begin tag (RE)
'end' => '/^\s*\?>/', // <?php			// end tag (RE)
'post' => 'gmlp_highlightstr',			// function call on block
'first' => 1,					// include begin line
'last' => 1,					// include end line
'newline' => 1,					// retain newlines
);

$gmlp_translate['blocks']['php2'] = array(
'begin' => '/^<php>/',
'end' => '/^<\/php>/',
'newline' => 1,
'post' => 'gmlp_highlightstr_php',
);

$gmlp_translate['blocks']['leadingspace'] = array(
'begin' => '/^\s{1,8}/',
'end' => '/(^\S+)/',
'pre' => '<pre>',
'replace' => 'htmlentities',			// function call on each line*
'post' => '</pre>',				// apped to block
'first' => 1,
'continue' => 1					// retain end line
);
// * not as efficient as applying the call to the entire block, but 'replace' 
// has dual role: function or string

$gmlp_translate['blocks']['pre'] = array(
'begin' => '/^<pre/',
'end' => '/^<\/pre>/',
'first' => 1,
'last' => 1,
'replace' => 'htmlentities',
'newline' => 1,
);

$gmlp_translate['blocks']['html'] = array(
'begin' => '/^<html>/',
'end' => '/^<\/html>/',
'pre' => '<pre>',
'post' => '</pre>',
'replace' => 'htmlentities',
);

$gmlp_translate['blocks']['skip'] = array(
'begin' => '/^``/',
'end' => '/^\'\'/',
'pre' => '<p>',
'post' => '</p>',
'replace' => '<br>',				// append to each line
);

$gmlp_translate['blocks']['comment'] = array(
'begin' => '/^<!--/',
'end' => '/^-->/',
'first' => 1,
'last' => 1,
);

$gmlp_translate['blocks']['phpcomment'] = array(
'begin' => '/^\/\*/',
'end' => '/^\*\//',
'pre' => "<pre>/*\n",
'post' => '</pre>',
'last' => 1,
);

$gmlp_translate['blocks']['list'] = array(
'begin' => '/^<list>/',
'end' => '/^<\/list>/',
'pre' => '<ul>',
'post' => '</ul>',
'replace' => 'gmlp_list',
'convert' => 1,				 	// apply 'inlines' 'chars'
);

$gmlp_translate['blocks']['ul'] = array(
'begin' => '/^<ul>/',
'end' => '/^<\/ul>/',
'pre' => '<ul>',
'post' => '</ul>',
'replace' => 'gmlp_list',
'convert' => 1,
);

$gmlp_translate['blocks']['dl'] = array(
'begin' => '/^<dl>/',
'end' => '/^<\/dl>/',
'first' => 1,
'last' => 1,
'replace' => 'gmlp_dlist',
'convert' => 1,				 
);

$gmlp_translate['blocks']['notes'] = array(
'begin' => '/^<notes>/',
'end' => '/^<\/notes>/',
'pre' => '<b><small>Notes</small></b><ol class="notes">',
'post' => '</ol>',
'replace' => 'gmlp_list',
'convert' => 1,				 
);

$gmlp_translate['blocks']['ini'] = array(
'begin' => '/^<ini>/',
'end' => '/^<\/ini>/',
'replace' => 'gmlp_ini',
'pre' => '<pre class="ini"><span>INI text</span>',
'post' => '</pre>',
);

$gmlp_translate['blocks']['code'] = array(
'begin' => '/^<code>/',
'end' => '/^<\/code>/',
'post' => 'gmlp_div_highlightstr_php',
'last' => 0,
'newline' => 1,
);

$gmlp_translate['blocks']['text'] = array(
'begin' => '/^<text>/',
'end' => '/^<\/text>/',
'pre' => '<pre class="text"><span>plain text</span>',
'post' => '</pre>',
'replace' => 'htmlentities',
);

$gmlp_translate['blocks']['blockquote'] = array(
'begin' => '/^<blockquote/',
'end' => '/^<\/blockquote>/',
'first' => 1,
'last' => 1,
'convert' => 1,
);

$gmlp_translate['blocks']['div'] = array(
'begin' => '/^<div/',
'end' => '/^<\/div>/',
'first' => 1,
'last' => 1,
'convert' => 1,
);

$gmlp_translate['blocks']['quote'] = array(
'begin' => '/^<quote>/',
'end' => '/^<\/quote>/',
'pre' => '<blockquote>',
'post' => '</blockquote>',
'convert' => 1,
);

// In order to enter lines of HTML, put it between <HTML> tags -- this 
// causes all lines to be used "as is" (and is slightly more efficient).

$gmlp_translate['blocks']['HTML'] = array(
'begin' => '/^<HTML>$/',
'end' => '/^<\/HTML>/',
);

// same as:

$gmlp_translate['blocks']['notranslate'] = array(
'begin' => '/^<notranslate>$/',
'end' => '/^<\/notranslate>/',
);

return 1;
